Page({

  data: {
    playing: false, // 是否正在进行中
    flashStatus: 'off', // 闪灯状态。默认关闭
    timeCountList: [{ // 闪光频次
      name: "快 速",
      time: [100, 200]
    }, {
      name: "中 速",
      time: [500, 600]
    },{
      name: "慢 速",
      time: [900, 1000]
    }],
  },
  // 改变闪灯频次。快闪、慢闪、常亮
  changeLight(e) {
    let {
      index
    } = e.currentTarget.dataset
    this.setData({
      playing: true
    })
    this.interval = setInterval(() => {
      this.setData({
        flashStatus: 'on'
      })
      setTimeout(() => {
        this.setData({
          flashStatus: 'off'
        })
      }, this.data.timeCountList[index].time[0]);
    }, this.data.timeCountList[index].time[1])
  },
  // 常亮
  changeLightToOnlight() {
    this.setData({
      playing: true,
      flashStatus: 'on'
    })
  },
  // 停止。清除计时器
  stop() {
    clearInterval(this.interval)
    this.setData({
      playing: false,
      flashStatus: 'off'
    })
  },
  onShareAppMessage() {
    return {
      title: "手机秒变闪光灯",
      path: "/pages/happyTools/pages/mobileFlash/index",
      imageUrl: '/images/function_icon/mobileFlash.png',
    }
  },
  onShareTimeline() {
    return {
      title: '手机秒变闪光灯',
      imageUrl: '/images/function_icon/mobileFlash.png',
    }
  },
});